<template>
  <div>
    
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>产品配置</el-breadcrumb-item> 
        <el-breadcrumb-item>测试工具</el-breadcrumb-item>
        <el-breadcrumb-item>用户删除</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <el-form ref="form" :model="form" label-width="80px" class="demo-form-inline">
        <el-form-item label="用户id">
          <el-input v-model="form.uid"></el-input>
        </el-form-item>

        <el-form-item label="用户信息:">
            <div>手机号={{user.phone}}</div>
            <div>昵称={{user.user_name}}</div>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" @click="onSubmit">删除</el-button>
          <el-button type="success" @click="onSubmitChange">检查用户</el-button>
        </el-form-item>
      </el-form>
    </basic-container>
  </div>
</template>
<script>
import { common } from "@/api/cat/httpRequest"; 
import { tools as baseURL } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      form: {},
      user: {}
    };
  },
  methods: {
    /** 检测用户 */
    async onSubmitChange(){
       if(this.form.uid==undefined){
        this.$message.error("请输入用户id")
        return;
      }
      let {data} = await common(baseURL.changeUser+'/'+this.form.uid, null, null, "GET");
      if (data == null || data.length==0) {
        this.user = {}
        this.$message.error("用户不存在")
        return;
      } 
      this.user = data;
    },
    async onSubmit() {
       if(this.form.uid==undefined){
        this.$message.error("请输入用户id")
        return;
      }

      let {data} = await common(baseURL.changeUser+'/'+this.form.uid, null, null, "GET");
      if (data == null || data.length==0) {
        this.user = {}
        this.$message.error("用户不存在")
        return;
      }
      //提示是否确定删除
      //删除
      this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
        type: "warning",
      })
      .then(async () => {
        let response = await common(baseURL.deleteUser+'/'+this.form.uid,null, null, "GET");
        if(response.code==1){
          this.user = {};
        }
      })
    }
  }
};
</script>